import {
  Message,
  MessageBox
} from 'element-ui'
import util from '@/libs/util.js'
import router from '@/router'
import {
  page
} from '@/api/chooseCourse/teSchool/index'
import {
  page_tea
} from '@/api/chooseCourse/teTeacher/index';
import {
  page_yuan
} from '@/api/chooseCourse/teDepartment/index';


export default {
  namespaced: true,
  state: {
    school: null,
    teacher: null,
    yuanxi: null,


  },
  actions: {
    async get_teacher({
      state,
      commit
    }) {


      let res = await page_tea()

      state.teacher = res.data
      let res1 = await page()
      state.school = res1.data
      let res2 = await page_yuan()
      state.yuanxi = res2.data

      console.log(state.teacher)
      // commit('set_teacher')

    },
    async get_school({
      state
    }) {
      if (state.school == null) {
        let res = await page()
        state.school = res.data
      }

    },
    async get_yuanxi({
      state,
      commit
    }) {
 
      let res = await page_yuan()
      localStorage.setItem('yuanxi', JSON.stringify(res.data))
      state.yuanxi = res.data
      let res1 = await page()
      state.school = res1.data

    },
    async get_teacher_yuanxi({
      state,
      commit
    }) {}


  },
  mutations: {
    set_teacher(state) {
      //根据学校id添加学校名称到教师属性
      state.teacher.forEach(item => {
        console.log(item)
        state.school.forEach(item1 => {
            if (item.schoolId == item1.id) {
              item.schoolName = item1.name
            }
          }),
          state.yuanxi.forEach(item2 => {
            if (item.collegeId == item2.id) {
              //响应式添加属性
              // this.$set(item,'xueyuan',item2.name)
              item.xueyuan = item2.name
            }
          })

      })
      localStorage.setItem('teacher', JSON.stringify(state.teacher))
      console.log(state.teacher)
    },

  }
}
